﻿'Digite o NameSpace: Babok
'Digite o nome da Classe de dominio: Requisito

'--TESTE:-----------
'    <TestMethod()> _
'    Public Sub SalvarRequisito()
'        Dim _Requisito As Requisito
'        _Requisito = New Requisito
'
'        _Requisito.Salvar()
'
'        Assert.IsTrue(_Requisito.Id.HasValue)
'    End Sub
<Serializable()> _
Public Class Requisito
    Inherits BaseDominio


    Private _descricao As String
    Public Overridable Property Descricao() As String
        Get
            Return _descricao
        End Get
        Set(ByVal value As String)
            _descricao = value
        End Set
    End Property


    Private _itemBackLog As ItemBackLog
    Public Overridable Property ItemBackLog() As ItemBackLog
        Get
            Return _itemBackLog
        End Get
        Set(ByVal value As ItemBackLog)
            _itemBackLog = value
        End Set
    End Property


#Region "Negocio"

    Protected Sub New()
        MyBase.New()
    End Sub

    Public Sub New(ByVal _descricao As String)
        MyBase.New()
        Me._descricao = _descricao
    End Sub

    Public Overridable Function Buscar(ByVal _id As Long) As Requisito
        Return MyBase.RequisitoDao.Buscar(_id)
    End Function

    Public Overridable Sub AlterarDescricao(ByVal _descricao As String)
        Me.Descricao = Trim(_descricao)
        MyBase.RequisitoDao.Alterar(Me)
    End Sub

    Public Shared Function BuscarPorId(ByVal _id As Long) As Requisito
        Dim _requisito As New Requisito
        Return _requisito.Buscar(_id)
    End Function

    Public Overridable Sub Salvar(ByVal _itemBackLog As ItemBackLog)
        If Not _itemBackLog.Id.HasValue Then
            Throw New ItemBacklogException("Não é possível salvar um requisito sem informar um item de backlog previamente salvo")
        End If
        Me.ItemBackLog = _itemBackLog
        MyBase.RequisitoDao.Salvar(Me)
    End Sub

    Public Overridable Sub Salvar()
        If Me.ItemBackLog Is Nothing Then
            Throw New ItemBacklogException("Não é possível salvar um requisito sem informar um item de backlog")
        End If
        MyBase.RequisitoDao.Salvar(Me)
    End Sub

#End Region

End Class

